#include "factory.h"

//任务入队
int taskEnQueue(taskQueue_t *pQueue,int new_fd)
{
    task_t *pnew=(task_t *)calloc(1,sizeof(task_t));
    pnew->new_fd=new_fd;
    pthread_mutex_lock(&pQueue->mutex);
    //尾插法
    if(!pQueue->pRear)
    {
        //队空
        pQueue->pFront=pnew;
        pQueue->pRear=pnew;
    }else{
        //队非空
        pQueue->pRear->pnext=pnew;
        pQueue->pRear=pnew;
    }
    pQueue->queueSize++;
    pthread_mutex_unlock(&pQueue->mutex);
    return 0;
}

//任务出队
int taskDequeue(taskQueue_t *pQueue,task_t **pnew)
{
    if(pQueue->queueSize)
    {
        *pnew=pQueue->pFront;
        pQueue->pFront=pQueue->pFront->pnext;
        pQueue->queueSize--;
        if(NULL==pQueue->pFront)//删除后队空
        {
            pQueue->pRear=NULL;
        }
    }else{
        return -1;
    }
    return 0;
}